<template>
  <div class="home-container">
    <van-nav-bar class="page-nav-bar">
      <van-button class="search-btn" to="/search" slot="title" icon="search" type="info">搜索</van-button>
    </van-nav-bar>
    <!--channels-->
    <van-tabs class="channels-tab" v-model="active" animated swipeable>
      <van-tab v-for="item in channels" :title="item.name" :key="item.id">
        <!--声明子组件-->
        <articleList :id="item.id" /> 
      </van-tab>
      <div slot="nav-right" class="pos"></div>
      <div slot="nav-right" class="hamburger-bar" @click="show = true">
        <i class="toutiao toutiao-gengduo"></i>
      </div>
    </van-tabs>
    <!--编频道弹出层-->
    <van-popup
      v-model="show"
      closeable
      position="bottom"
      :style="{ height: '100%' }"
    >
    <channelEdit :myChannels="channels"></channelEdit>
    </van-popup>
  </div>
</template>

<script>
import { getUserChannels } from '@/api/channel.js'
import articleList from './components/article-list.vue'
import channelEdit from './components/channel-edit.vue'
export default {
  // 定义属性
  data() {
    return {
      active: 0,
      channels:[],
      list:[],
      show:false
    }
  },
  // 注册组件
  components:{
    articleList,
    channelEdit
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {
  },
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    async channelList () {
      try {
        const result = await getUserChannels()
        this.channels = result.data.data.channels
      } catch (error) {
        console.log('error', error)
      }
    }
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.channelList()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  }
}
</script>

<style lang='less'>
.home-container{
  padding-bottom: 100px;
  .van-nav-bar__title{
    max-width: unset;
  }
  .search-btn{
    width: 555px;
    height: 64px;
    background-color: #5babfb;
    border-radius: 32px;
    color: #ffffff;
    border: none;
    font-size: 28px;
    .van-icon{
      color: #ffffff;
      font-size: 32px;
    }
  }
.channels-tab{
  .van-tab{
    min-width: 200px;
    height: 80px;
    color: #777777;
    font-size: 28px;
    border-right: 1px solid #edeff3;
  }
  .van-tab--active{
      color: #333333;
      font-size: 30px;
    }
  .van-tabs__nav{
    align-items: center;
  }
  .van-tabs__nav--line{
    padding-bottom: unset;
  }
  .van-tabs__line{
    bottom: 9px;
    width: 31px;
    height: 6px;
    background-color: #3296fa;
    border-radius: 3px;
  }
  .hamburger-bar{
    position: fixed;
    right: 0;
    width: 66px;
    height: 83px;
    background: #ffffff;
    opacity: 0.9;
    display: flex;
    align-items: center;
    .toutiao{
      font-size: 40px;
    }
  }
  .hamburger-bar:before{
    content: '';
    width: 1px;
    height: 58px;
    margin-right: 16px;
    background-image: url('~@/assets/gradient-gray-line.png');
    background-size: contain;
  }

  .pos{
    width: 66px;
    height: 83px;
    flex-shrink: 0;
  }
}

}
</style>